<template>
    <view class="webview">
        <web-view class="webview__wb" @load="handleLoad" v-if="url" :src="url" /> 
        <view @click="handleCopy" class="webview__button">
            <image
            class="webview__icon"
                src="@/static/copy.png"
                mode="scaleToFill"
            />
        </view>
    </view>
</template>

<script setup lang="ts">
import { showToast } from '@/utils/helper';
import { onLoad } from '@dcloudio/uni-app'
const url = ref('')
const options = ref<{ url?:string }>(null)
onLoad((params:any) => {
    options.value = params
    if(!params.url) {
        showToast('地址不存在')
        return 
    }
    url.value = params.url
    uni.showLoading({
        title: '加载中...',
    })
    setTimeout(handleLoad,3000)
})
const handleLoad = ()=> {
    uni.hideLoading()
}
const handleCopy = ()=> {
    const url = options?.value?.url || ''
    if(url) {
        uni.setClipboardData({
            "data": url,
        })
    }
}
</script>

<style lang="scss" scoped>
.webview {
    position: relative;
    &__wb {
        height: 100vh;
        width: 100vw;
    }
    &__button {
        position: fixed;
        right: 8rpx;
        bottom: 200rpx;
        z-index: 999;
        background-color: $uni-color-primary;
        border-radius: 50%;
        padding: 20rpx;
        width: 60rpx;
        height: 60rpx;
    }
    &__icon {
        width: 100%;
        height: 100%;
    }
}
</style>